Page({
  data: {
    favorites: []
  },

  onLoad: function (options) {
    this.loadFavorites();
  },

  onShow: function () {
    this.loadFavorites();
  },

  // 加载收藏数据
  loadFavorites: function () {
    const favorites = wx.getStorageSync('favorites') || [];
    this.setData({
      favorites: favorites
    });
  },

  // 取消收藏
  removeFavorite: function (e) {
    const index = e.currentTarget.dataset.index;
    wx.showModal({
      title: '提示',
      content: '确定要取消收藏吗？',
      success: (res) => {
        if (res.confirm) {
          let favorites = this.data.favorites;
          favorites.splice(index, 1);
          wx.setStorageSync('favorites', favorites);
          this.setData({
            favorites: favorites
          });
          wx.showToast({
            title: '已取消收藏',
            icon: 'success'
          });
        }
      }
    });
  },

  // 跳转到商品详情
  goToDetail: function (e) {
    const nencode = e.currentTarget.dataset.nencode;
    wx.navigateTo({
      url: '/pages/Product_details/Product_details?nencode=' + nencode
    });
  }
}); 